package cn.lyq.card.ui.rank

import cn.lyq.card.R
import cn.lyq.card.data.model.RankTypeInfo
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder


class RankTypeAdapter : BaseQuickAdapter<RankTypeInfo, BaseViewHolder>
    (R.layout.item_rank_type, mutableListOf()) {

    var selectIndex = 0

    fun update(index: Int): Boolean {
        if (index != selectIndex) {
            val temp = selectIndex
            selectIndex = index
            notifyItemChanged(temp)
            notifyItemChanged(index)
            return true
        }
        return false
    }

    override fun convert(holder: BaseViewHolder, item: RankTypeInfo) {
        holder.setVisible(R.id.tvSelected, holder.adapterPosition == selectIndex)
        holder.setText(R.id.tvTypeName, item.name)
    }
}